<?php
declare(strict_types=1);

namespace App\Controller\Common;
use App\Controller\AbstractController;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\Di\Annotation\Inject;
use Service\FileService\FileLocalService;

/**
 * 本地文件上传接口
 * @author chenshubo
 * @Controller(prefix="/common/upload")
 */
class UploadController extends AbstractController
{
    /**
     * @Inject()
     * @var FileLocalService
     */
    protected $fileLocalService;
    
    /**
     * 上传图片资源
     * @RequestMapping(path="uploadLocalFile", methods="post")
     */
    public function uploadLocalFile(RequestInterface $request)
    {
        $file = $request->file('file');
        return $this->fileLocalService->upload(
            $request->input('type'),
            $request->file('file')
        );
    }
}